package com.moyou.weichat.utils;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

/**
 * Created by Administrator on 2017/10/17 0017.
 * sj: 2017年10月17日14:01:58
 * name : ts：
 *  用途： RecyclerView的帮助类
 */

public class RecyclerViewHoper {

    private static  RecyclerViewHoper recyclerViewHoper;
    //返回一个单利对象
    public static  RecyclerViewHoper getSingleHoper(){
        return recyclerViewHoper == null ? recyclerViewHoper =
                new RecyclerViewHoper(): recyclerViewHoper;
    }

    /**
     * 配置瀑布流列表RecyclerView
     * @param view
     */
    public  void initRecyclerViewSV(RecyclerView view,
                                          RecyclerView.Adapter adapter, int column, boolean nestedScrollingEnabled) {
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(column, StaggeredGridLayoutManager.VERTICAL);
        view.setLayoutManager(layoutManager);
        //   layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
        ((DefaultItemAnimator) view.getItemAnimator()).setSupportsChangeAnimations(false);
        view.setNestedScrollingEnabled(nestedScrollingEnabled);
        view.setAdapter(adapter);
    }

    /**
     * 配置网格列表RecyclerView
     *
     * @param view
     */
    public  void initRecyclerViewG(Context context, RecyclerView view,
                                         RecyclerView.Adapter adapter, int column) {
        GridLayoutManager layoutManager = new GridLayoutManager(context, column, LinearLayoutManager.VERTICAL, false);
        ((DefaultItemAnimator) view.getItemAnimator()).setSupportsChangeAnimations(false);
        view.setLayoutManager(layoutManager);
        view.setAdapter(adapter);
    }
    public  void initRecyclerViewG(Context context, RecyclerView view,
                                         RecyclerView.Adapter adapter, int column,boolean b) {
        initRecyclerViewG(context,view,adapter,column);
        view.setNestedScrollingEnabled(b);

    }


    /**
     * 配置水平列表RecyclerView
     *
     * @param view
     */
    public  void initRecyclerViewH(Context context, RecyclerView view,
                                         RecyclerView.Adapter adapter) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        ((DefaultItemAnimator) view.getItemAnimator()).setSupportsChangeAnimations(false);
        view.setLayoutManager(layoutManager);
        view.setAdapter(adapter);
    }
    /**
     * 配置水平列表RecyclerView
     *
     * @param view
     */
    public  void initRecyclerViewH(Context context, RecyclerView view,
                                         RecyclerView.Adapter adapter,boolean b) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,b);
        ((DefaultItemAnimator) view.getItemAnimator()).setSupportsChangeAnimations(false);
        view.setLayoutManager(layoutManager);
        view.setAdapter(adapter);
    }
    /**
     * 配置垂直列表RecyclerView
     *VERTICAL Vertical
     * @param view
     */
    public  void initRecyclerViewV(Context context, RecyclerView view,
                                         RecyclerView.Adapter adapter) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        ((DefaultItemAnimator) view.getItemAnimator()).setSupportsChangeAnimations(false);
        view.setLayoutManager(layoutManager);
        view.setAdapter(adapter);
    }

    public  void initRecyclerViewV(Context context, RecyclerView view,
                                         RecyclerView.Adapter adapter, boolean b) {
        initRecyclerViewV(context, view, adapter);
        view.setNestedScrollingEnabled(b);
    }

}
